package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.MesTaskCard;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.MesWork;
import com.ruoyi.system.service.IMesWorkService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 报工Controller
 * 
 * @author ruoyi
 * @date 2024-06-01
 */
@RestController
@RequestMapping("/system/work")
public class MesWorkController extends BaseController
{
    @Autowired
    private IMesWorkService mesWorkService;

    /**
     * 查询报工列表
     */
    @PreAuthorize("@ss.hasPermi('system:work:list')")
    @GetMapping("/list")
    public TableDataInfo list(MesWork mesWork)
    {
        startPage();
        List<MesWork> list = mesWorkService.selectMesWorkList(mesWork);
        return getDataTable(list);
    }

    /**
     * 导出报工列表
     */
    @PreAuthorize("@ss.hasPermi('system:work:export')")
    @Log(title = "报工", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MesWork mesWork)
    {
        List<MesWork> list = mesWorkService.selectMesWorkList(mesWork);
        ExcelUtil<MesWork> util = new ExcelUtil<MesWork>(MesWork.class);
        util.exportExcel(response, list, "报工数据");
    }

    /**
     * 获取报工详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:work:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return AjaxResult.success(mesWorkService.selectMesWorkById(id));
    }

    /**
     * 新增报工
     */
    @PreAuthorize("@ss.hasPermi('system:work:add')")
    @Log(title = "报工", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MesWork mesWork)
    {
        return toAjax(mesWorkService.insertMesWork(mesWork));
    }

    /**
     * 修改报工
     */
    @PreAuthorize("@ss.hasPermi('system:work:edit')")
    @Log(title = "报工", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MesWork mesWork)
    {
        return toAjax(mesWorkService.updateMesWork(mesWork));
    }

    /**
     * 删除报工
     */
    @PreAuthorize("@ss.hasPermi('system:work:remove')")
    @Log(title = "报工", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(mesWorkService.deleteMesWorkByIds(ids));
    }


    //查询任务卡的报工信息
    @GetMapping("/work/process/list")
    public AjaxResult workProcessList(@RequestParam("taskCardId") String taskCardId) {

        List<String> workList = mesWorkService.workProcessList(taskCardId);
        return AjaxResult.success(workList);
    }
}
